<html>
<head>
    <title>用户列表</title>
    <#include "/common/import.ftl" >
    <script type="text/javascript">
        var pluginsSwitch = "${pluginsSwitch!''}";
        $(function () {
            $('#userList').datagrid({
                toolbar: [
                    {
                        text: '增加',
                        iconCls: 'icon-add',
                        handler: function () {
                            saveUser('add');
                        }
                    }
                    , '-',
                    {
                        text: '删除',
                        iconCls: 'icon-cut',
                        handler: function () {
                            deleteUser();
                        }
                    }
                    , '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            saveUser('edit');
                        }
                    }
                    , '-',
                    {
                        text: '刷新',
                        iconCls: 'icon-reload',
                        handler: function () {
                            reload();
                        }
                    }, '-',
                    {
                        text: '用户权限',
                        iconCls: 'icon-rights',
                        handler: function () {
                            userRitht();
                        }
                    }
                ],
                onDblClickRow: function (row) {
                    saveUser('edit');
                }
            });

            $('#userList').datagrid('getPanel').panel({
                onExpand: function () {
                    $('#userActWin').panel('close');
                }
            });

            var p = $('#userList').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    onBeforeRefresh: function () {
                    }
                });
            }
        });

        $(function () {
            $('#userActWin').panel({
                onClose: function () {
                    $('#userList').datagrid('getPanel').panel('expand');
                },
                onExpand: function () {
                    $('#userList').datagrid('getPanel').panel('collapse');
                },
                onCollapse: function () {
                    $('#userList').datagrid('getPanel').panel('expand');
                }
            });
        });

        function reload() {
            $('#userList').datagrid('reload');
        }

        //新的查询功能
        function searchUserNew() {
            $('#userList').datagrid('options').pageNumber = parseInt("1");
            var queryParams = $('#userList').datagrid('options').queryParams;
            queryParams.userId = $('#userId').val();
            queryParams.userEname = $('#userEname').val();
            queryParams.userCname = $('#userCname').val();
            if ("1" == pluginsSwitch) {
                queryParams.orgId = $('#orgId').combobox('getValue');
            }
            var options = $('#userList').datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            options.total = 0;
            options.pageSize = 10;
            $('#userList').datagrid("reload");
        }

        function clearSearch() {
            $('#userEname').val('');
            $('#userCname').val('');
            $('#userId').val('');
            $('#orgId').combobox('setValue', '');
        }

        function saveUser(paraFlag) {
            $('#userAddFrame').html('');
            var url = '${ctx}/uct/user/add.action';
            if ('edit' == paraFlag) {
                var node = getSelected();
                if (node) {
                    url = '${ctx}/uct/user/add.action?id=' + node.userId;
                    $('#userAddFrame').attr("src", url);
                    $('#userAddWin').window('open');
                }
            } else {
                $('#userAddFrame').attr("src", url);
                $('#userAddWin').window('open');
            }
        }

        function userRitht() {
            var node = getSelected();
            if (node) {
                if (node.userEname == "${loginUser.user.userEname}") {
                    $.messager.alert('提示', '不能给自己授权', 'info');
                } else {
                    var op = "all";
                    var url = '${ctx}/uct/core/user-right.action?op=' + op + '&userId=' + node.userId;
                    $('#userActFrame').attr("src", url);
                    $('#userActWin').panel('open');
                    $('#userActWin').panel('setTitle', '用户权限[<font color=red>' + node.userCname + '</font>]');
                    $('#userList').datagrid('getPanel').panel('collapse');
                }
            }
        }

        function getSelected() {
            var selected = $('#userList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        function deleteUser() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color="red">' + node.userCname + '</font> ?', function (r) {
                    if (r) {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/uct/user/userDel.action?id=" + node.userId,
                            success: function (data) {
                                var result = jQuery.parseJSON(data);
                                if (result.flag == 'T') {
                                    $.messager.alert('提交结果', result.msg, 'info');
                                    var rowIndex = $('#userList').datagrid('getRowIndex', node);
                                    $('#userList').datagrid('deleteRow', rowIndex);
                                } else {
                                    $.messager.alert('提交结果', '操作失败:' + result.msg, 'error');
                                }
                            }
                        });
                    }
                });
            }
        }

        function closeUserAdd() {
            $('#userAddWin').window('close');
        }
    </script>
</head>

<body>
<table class="planel-body">
    <tr>
        <td>用户账号</td>
        <td>
            <input id="userEname" name="userEname" value=""/>
        </td>
        <td>用户姓名</td>
        <td>
            <input id="userCname" name="userCname" value=""/>
        </td>
        <#if '1'== pluginsSwitch>
            <td> 所属机构</td>
            <td>
                <select id="orgId" name="orgId" style="width:184px;"></select>
            </td>
        </#if>
        <td>
            <a class="easyui-linkbutton" iconCls="icon-search"
               onclick="searchUserNew();">查询</a>
            <a class="easyui-linkbutton" iconCls="" onclick="clearSearch();">清空</a>
        </td>
    </tr>
</table>
<table id="userList" class="easyui-datagrid" title="用户列表"
       data-options="rownumbers:true,singleSelect:true,pageList:[10,15,30],pagination:true,url:'${ctx}/uct/user/user!data.action'">
    <thead>
    <tr>
        <th data-options="field:'userEname',width:140">用户账号</th>
        <th data-options="field:'userCname',width:100">用户姓名</th>
        <th data-options="field:'orgEname',width:100">所属机构</th>
        <th data-options="field:'deptName',width:150">所属部门</th>
        <th data-options="field:'fax',width:100">上级领导</th>
        <th data-options="field:'userType',width:110">用户类型</th>
        <th data-options="field:'userSex',width:80,
						formatter:function(value){
							if( value=='F'){
								return '女';
							}else if(value=='M'){
								return '男';
							}else{ 
								return '';
							}
						}">性别
        </th>
        <th data-options="field:'mobile',width:120">手机</th>
        <th data-options="field:'userStatus',width:100,
						formatter:function(value){
							if( value=='1'){
								return '<font color=blue>启用</font>';
							}else{ 
								return '<font color=red>停用</font>';
							}
						}
						">状态
        </th>
    </tr>
    </thead>
</table>

<div id="userActWin" class="easyui-panel" title="用户权限" icon="icon-lock" collapsible="false"
     closed="true"
     closable="true" style="padding:5px;background:#fafafa;height:600px;overflow: hidden;">
    <iframe frameborder="0" id="userActFrame" height="100%" width="100%" scrolling="yes"
            frameborder="0"></iframe>

</div>

<div id="userAddWin" class="easyui-window" title="用户信息"
     style="padding:5px;width: 460px;height:510px;top: 5px;overflow: hidden;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <iframe frameborder="0" id="userAddFrame" height="100%" width="100%" scrolling="yes"
            frameborder="0"></iframe>
</div>
</body>
<script>
    function initOrg() {
        //初始化组织pluginsSwitch
        var url = "${ctx}/uct/org/org!initOrg.action";
        if ("1" == pluginsSwitch && "1" != "${sysUser!''}") {
            url = url + "?orgId=${loginUser.user.orgId}";
        }
        $('#orgId').combobox({
            url: url,
            valueField: 'orgId',
            textField: 'orgCname'
        });
    }

    if ("1" == pluginsSwitch) {
        $(function () {
            initOrg();
        });
    }
</script>

<script type="text/javascript" src="${ctx }/js/jquery-md5-min.js"></script>
<script type="text/javascript" src="${ctx}/js/uct//uct_form.js"></script>
<script type="text/javascript" src="${ctx}/js/uct/date.js"></script>
<script type="text/javascript" src="${ctx}/js/utiltools.js"></script>
</html>